home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
cal-mayan.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-01-20
|
16KB
|
383 lines
;;; cal-mayan.el --- calendar functions for the Mayan calendars.
;; Copyright (C) 1992, 1993, 1995 Free Software Foundation, Inc.
;; Author: Stewart M. Clamen <clamen@cs.cmu.edu>
;; Edward M. Reingold <reingold@cs.uiuc.edu>
;; Keywords: calendar
;; Human-Keywords: Mayan calendar, Maya, calendar, diary
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This collection of functions implements the features of calendar.el and
;; diary.el that deal with the Mayan calendar. It was written jointly by
;; Stewart M. Clamen School of Computer Science
;; clamen@cs.cmu.edu Carnegie Mellon University
;; 5000 Forbes Avenue
;; Pittsburgh, PA 15213
;; and
;; Edward M. Reingold Department of Computer Science
;; (217) 333-6733 University of Illinois at Urbana-Champaign
;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
;; Urbana, Illinois 61801
;; Comments, improvements, and bug reports should be sent to Reingold.
;; Technical details of the Mayan calendrical calculations can be found in
;; ``Calendrical Calculations, Part II: Three Historical Calendars''
;; by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
;; pages 383-404.
;;; Code:
(require 'calendar)
(defconst calendar-mayan-days-before-absolute-zero 1137140
"Number of days of the Mayan calendar epoch before absolute day 0.
According to the Goodman-Martinez-Thompson correlation. This correlation is
not universally accepted, as it still a subject of astro-archeological
research. Using 1232041 will give you Spinden's correlation; using
1142840 will give you Hochleitner's correlation.")
(defconst calendar-mayan-haab-at-epoch '(8 . 18)
"Mayan haab date at the epoch.")
(defconst calendar-mayan-haab-month-name-array
["Pop" "Uo" "Zip" "Zotz" "Tzec" "Xul" "Yaxkin" "Mol" "Chen" "Yax"
"Zac" "Ceh" "Mac" "Kankin" "Muan" "Pax" "Kayab" "Cumku"])
(defconst calendar-mayan-tzolkin-at-epoch '(4 . 20)
"Mayan tzolkin date at the epoch.")
(defconst calendar-mayan-tzolkin-names-array
["Imix" "Ik" "Akbal" "Kan" "Chicchan" "Cimi" "Manik" "Lamat" "Muluc" "Oc"
"Chuen" "Eb" "Ben" "Ix" "Men" "Cib" "Caban" "Etznab" "Cauac" "Ahau"])
(defun calendar-mayan-long-count-from-absolute (date)
"Compute the Mayan long count corresponding to the absolute DATE."
(let ((long-count (+ date calendar-mayan-days-before-absolute-zero)))
(let* ((baktun (/ long-count 144000))
(remainder (% long-count 144000))
(katun (/ remainder 7200))
(remainder (% remainder 7200))
(tun (/ remainder 360))
(remainder (% remainder 360))
(uinal (/ remainder 20))
(kin (% remainder 20)))
(list baktun katun tun uinal kin))))
(defun calendar-mayan-long-count-to-string (mayan-long-count)
"Convert MAYAN-LONG-COUNT into traditional written form."
(apply 'format (cons "%s.%s.%s.%s.%s" mayan-long-count)))
(defun calendar-string-to-mayan-long-count (str)
"Given STR, a string of format \"%d.%d.%d.%d.%d\", return list of nums."
(let ((rlc nil)
(c (length str))
(cc 0))
(condition-case condition
(progn
(while (< cc c)
(let* ((start (string-match "[0-9]+" str cc))
(end (match-end 0))
datum)
(setq datum (read (substring str start end)))
(setq rlc (cons datum rlc))
(setq cc end)))
(if (not (= (length rlc) 5)) (signal 'invalid-read-syntax nil)))
(invalid-read-syntax nil))
(reverse rlc)))
(defun calendar-mayan-haab-from-absolute (date)
"Convert absolute DATE into a Mayan haab date (a pair)."
(let* ((long-count (+ date calendar-mayan-days-before-absolute-zero))
(day-of-haab
(% (+ long-count
(car calendar-mayan-haab-at-epoch)
(* 20 (1- (cdr calendar-mayan-haab-at-epoch))))
365))
(day (% day-of-haab 20))
(month (1+ (/ day-of-haab 20))))
(cons day month)))
(defun calendar-mayan-haab-difference (date1 date2)
"Number of days from Mayan haab DATE1 to next occurrence of haab date DATE2."
(mod (+ (* 20 (- (cdr date2) (cdr date1)))
(- (car date2) (car date1)))
365))
(defun calendar-mayan-haab-on-or-before (haab-date date)
"Absolute date of latest HAAB-DATE on or before absolute DATE."
(- date
(% (- date
(calendar-mayan-haab-difference
(calendar-mayan-haab-from-absolute 0) haab-date))
365)))
(defun calendar-next-haab-date (haab-date &optional noecho)
"Move cursor to next instance of Mayan HAAB-DATE.
Echo Mayan date if NOECHO is t."
(interactive (list (calendar-read-mayan-haab-date)))
(calendar-goto-date
(calendar-gregorian-from-absolute
(calendar-mayan-haab-on-or-before
haab-date
(+ 365
(calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
(or noecho (calendar-print-mayan-date)))
(defun calendar-previous-haab-date (haab-date &optional noecho)
"Move cursor to previous instance of Mayan HAAB-DATE.
Echo Mayan date if NOECHO is t."
(interactive (list (calendar-read-mayan-haab-date)))
(calendar-goto-date
(calendar-gregorian-from-absolute
(calendar-mayan-haab-on-or-before
haab-date
(1- (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
(or noecho (calendar-print-mayan-date)))
(defun calendar-mayan-haab-to-string (haab)
"Convert Mayan haab date (a pair) into its traditional written form."
(let ((month (cdr haab))
(day (car haab)))
;; 19th month consists of 5 special days
(if (= month 19)
(format "%d Uayeb" day)
(format "%d %s"
day
(aref calendar-mayan-haab-month-name-array (1- month))))))
(defun calendar-mayan-tzolkin-from-absolute (date)
"Convert absolute DATE into a Mayan tzolkin date (a pair)."
(let* ((long-count (+ date calendar-mayan-days-before-absolute-zero))
(day (calendar-mod
(+ long-count (car calendar-mayan-tzolkin-at-epoch))
13))
(name (calendar-mod
(+ long-count (cdr calendar-mayan-tzolkin-at-epoch))
20)))
(cons day name)))
(defun calendar-mayan-tzolkin-difference (date1 date2)
"Number of days from Mayan tzolkin DATE1 to next occurrence of tzolkin DATE2."
(let ((number-difference (- (car date2) (car date1)))
(name-difference (- (cdr date2) (cdr date1))))
(mod (+ number-difference
(* 13 (mod (* 3 (- number-difference name-difference))
20)))
260)))
(defun calendar-mayan-tzolkin-on-or-before (tzolkin-date date)
"Absolute date of latest TZOLKIN-DATE on or before absolute DATE."
(- date
(% (- date (calendar-mayan-tzolkin-difference
(calendar-mayan-tzolkin-from-absolute 0)
tzolkin-date))
260)))
(defun calendar-next-tzolkin-date (tzolkin-date &optional noecho)
"Move cursor to next instance of Mayan TZOLKIN-DATE.
Echo Mayan date if NOECHO is t."
(interactive (list (calendar-read-mayan-tzolkin-date)))
(calendar-goto-date
(calendar-gregorian-from-absolute
(calendar-mayan-tzolkin-on-or-before
tzolkin-